Skip to main content

All Questions

4votes
4answers
2kviews

Matching words from a text with a big list of keywords in Python

I implemented the following code to retrieve medication names from a given text (prescription_text in the code). It works by matching words in the text with a list ...
cuzureau's user avatar
4votes
1answer
4kviews

Finding Pattern Score in Python

I saw this problem in C++ on here and decided to try it in Python, which was much simpler. I've used the same problem blurb as in the link above, so they are consistent. I'm sure my code can be ...
Tennis Tubbies's user avatar
1vote
1answer
126views

Short function to remove unnecessary whitespace

I have a function consisting of one line of code: def trimString(string): """ Remove unnecessary whitespace. """ return re.sub('\s+', ' ', string).strip() ...
Crayo's user avatar
7votes
3answers
4kviews

Elegant way to replace substring in a regex with optional groups in Python?

Given a string taken from the following set: strings = [ "The sky is blue and I like it", "The tree is green and I love it", "A lemon is yellow" ] I ...
Delgan's user avatar
10votes
1answer
1kviews

Osherove TDD Kata 1: String Calculator

I implemented Roy Osherove's TDD Kata 1: String Calculator using Python 3.5.2 and the unittest module. The full description can be found at the link, it's a bit ...
Phrancis's user avatar

close